package com.bao.Servlet;

import com.bao.Service.AgencyService;
import com.bao.Service.RegionService;
import com.bao.ServiceImpl.AgencyServiceImpl;
import com.bao.ServiceImpl.RegionServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by TangBaoshan on 2018/8/14.
 */
@WebServlet(name = "FindRegionCityServlet")
public class FindRegionCityServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        request.setCharacterEncoding("utf-8");
        RegionService regionService = new RegionServiceImpl();
        AgencyService agencyService = new AgencyServiceImpl();
        int count=0;
        if (request.getParameter("city") == null && request.getParameter("province") != null) {
            int drank = 1;
            String pro = request.getParameter("province");
            int proid = regionService.findregionid(pro);
             count=agencyService.findregionNum(drank,proid);

        } else if (request.getParameter("city") != null && request.getParameter("province") != null) {
            int drank = 2;
            String city = request.getParameter("city");
            int citys = regionService.findregionid(city);
            count=agencyService.findregionNum(drank,citys);
        }
        out.print(count);
        out.flush();
        out.close();

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
